package com.soft.base.mail;

import com.xiaoleilu.hutool.extra.mail.MailAccount;
import com.xiaoleilu.hutool.extra.mail.MailUtil;
/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class SmtpMail {

    private MailAccount account = new MailAccount();

    public static SmtpMail create() {
        SmtpMail mail = new SmtpMail();
        mail.account.setAuth(true);
        return mail;
    }

    public SmtpMail host(String host) {
        account.setHost(host);
        return this;
    }

    public SmtpMail port(Integer port) {
        account.setPort(port);
        return this;
    }

    public SmtpMail ssl(Boolean ssl) {
        account.setStartttlsEnable(ssl);
        return this;
    }

    public SmtpMail user(String user) {
        account.setUser(user);
        account.setFrom(user);
        return this;
    }

    public SmtpMail pass(String pass) {
        account.setPass(pass);
        return this;
    }

    public SmtpMail from(String from) {
        account.setFrom(from);
        return this;
    }

    public SmtpMail send(String to, String subject, String html) {
        MailUtil.send(account, to, subject, html, true);
        return this;
    }

}
